//设定路由跳转时的钩子
import Vue from 'vue'
import Router from 'vue-router'
import routerMap from './routerMap'

Vue.use(Router);
const routes = new Router({
  ...routerMap,
});
export default (store) => {
  //配置路由钩子
  routes.beforeEach(function (to, from, next) {
    const { path } = to;
    if (store.state.userState.userData.authority === 0) {
      //普通用户进入后台需要做限制
      if (path === '/backstage-login' || path.indexOf("backstage") === -1) {
        next();
      } else {
        next('/backstage-login');
      }
    } else {
      next()
    }
  });
  /*  routes.afterEach(function (to) {
    store.commit('updateLoadingStatus', {isLoading: false})
  }); */
  return routes;
}
